package com.lhsy.djcloud.controller;

import cn.hutool.json.JSONUtil;
import com.lhsy.djcloud.common.SecurityConstant;
import com.lhsy.djcloud.entity.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

@Controller
public class BaseController {
    @Autowired protected StringRedisTemplate redisTemplate;

    public UserDto getCurrUser(HttpServletRequest request){
        String accessToken = request.getHeader("accessToken");
        String s = redisTemplate.opsForValue().get(SecurityConstant.TOKEN__USER_PRE + accessToken);
        UserDto merchantUserDto = JSONUtil.toBean(s, UserDto.class);
        return merchantUserDto;
    }
}


